<ion-header>
    <ion-toolbar>
        <ion-buttons slot="start">
            <ion-back-button [text]="'core.back' | translate" />
        </ion-buttons>
        <ion-title>
            <h1>{{ 'core.courses.availablecourses' | translate }}</h1>
        </ion-title>
        <ion-buttons slot="end">
            <core-context-menu>
                @if (downloadCourseEnabled || downloadCoursesEnabled) {
                    <core-context-menu-item [priority]="1000" [content]="'core.settings.showdownloadoptions' | translate"
                        (action)="toggleDownload()" iconAction="toggle" [(toggle)]="downloadEnabled" />
                }
            </core-context-menu>
            <core-user-menu-button />
        </ion-buttons>
    </ion-toolbar>
</ion-header>
<ion-content>
    <ion-refresher slot="fixed" [disabled]="!loaded" (ionRefresh)="refreshCourses($event.target)">
        <ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}" />
    </ion-refresher>

    @if (searchEnabled) {
        <core-search-box (searchTextChange)="search($event)" [placeholder]="'core.courses.search' | translate"
            [searchLabel]="'core.courses.search' | translate" [autoFocus]="searchMode && !searchText" searchArea="CoreCoursesSearch"
            [searchText]="searchText" />
    }
    <ion-item class="ion-text-wrap" lines="none">
        <ion-toggle [(ngModel)]="showOnlyEnrolled" (ionChange)="toggleEnrolled()">
            {{ 'core.courses.showonlyenrolled' | translate }}
        </ion-toggle>
    </ion-item>

    <core-loading [hideUntil]="loaded" [message]="loadingMessage" placeholderType="column" placeholderHeight="108px">
        @if (searchMode && searchTotal > 0) {

            <ion-item-divider>
                <ion-label>
                    <h2 role="status">{{ 'core.courses.totalcoursesearchresults' | translate:{$a: searchTotal} }}</h2>
                </ion-label>
            </ion-item-divider>

        }

        <ion-list class="list-item-limited-width core-course-list">
            @for (course of courses; track course.id) {
                <core-courses-course-list-item [course]="course" [showDownload]="downloadEnabled" />
            }
        </ion-list>

        <core-infinite-loading [enabled]="canLoadMore" (action)="loadMoreCourses($event)" [error]="loadMoreError" />


        @if (searchMode && !courses.length) {
            <core-empty-box icon="fas-magnifying-glass" [message]="'core.courses.nosearchresults' | translate" role="alert" />
        }

        @if (!searchMode && !courses.length) {
            <core-empty-box icon="fas-graduation-cap" [message]="'core.courses.nocourses' | translate" />
        }

    </core-loading>
</ion-content>
